package com.xinchuang.mapper.targetSystem;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinchuang.entity.targetSystem.system.*;
import com.xinchuang.entity.targetSystem.target.TargetData;
import com.xinchuang.entity.targetSystem.target.TargetIndexList;
import com.xinchuang.entity.targetSystem.target.TargetInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName SystemsMapper
 * @Description: 体系主表
 * @auther xukl
 * @data 2021/3/30  17:39
 * @Version V1.0
 */
public interface SystemsMasterMapper extends BaseMapper<SystemsMaster> {

    @Insert(value = {
            "INSERT INTO systems_master ",
            "(sys_id,systems_name,include_type,include,stat,create_time,update_time,remark) ",
            "VALUES ",
            "(#{sysId},#{systemsName},#{includeType},#{include},#{stat},#{createTime},#{updateTime},#{remark})",
    })
    int save(SystemsMaster systemMaster);

    @Select(value = {
            "SELECT sys_id,systems_name,include_type,include,stat,create_time,update_time,remark FROM systems_master WHERE sys_id = #{sysId} "
    })
    @Results(id = "commonResultMap", value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "include", column = "include"),
            @Result(property = "stat", column = "stat"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "remark", column = "remark")
    })
    SystemsMaster findSystemsMasterById(String sysId);

    @Delete(value = "DELETE FROM systems_master WHERE sys_id = #{sysId}")
    int deleteById(String sysId);

    @Update(value = {
            "<script>",
            "UPDATE systems_master ",
            "<set>",
            "<if test = 'systemsName != null'>systems_name = #{systemsName},</if>",
            "<if test = 'includeType != null'>include_type = #{includeType},</if>",
            "<if test = 'include != null'>include = #{include},</if>",
            "<if test = 'stat != null'>stat = #{stat},</if>",
            "<if test = 'createTime != null'>create_time = #{createTime},</if>",
            "<if test = 'updateTime != null'>update_time = #{updateTime},</if>",
            "<if test = 'remark != null'>remark = #{remark},</if>",
            "</set>",
            "WHERE sys_id = #{sysId}",
            "</script>"
    })
    int update(SystemsMaster systemsMaster);


    /**
     * 更新缩略图
     */
    @Update(value = {
            "UPDATE systems_master SET ",
            "icon = #{icon},icon_url = #{iconUrl} ",
            "WHERE s_id = #{sId}"
    })
    int updateIcon(SystemsMaster systemsMaster);

    /**
     * 查询单个体系
     */
    @Select(value = {
            "SELECT sys_id,systems_name,include_type,remark,icon,icon_url ",
            "FROM systems_master WHERE sys_id = #{sysId} LIMIT 1"
    })
    @Results(id = "rapexMap", value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "iconUrl", column = "icon_url")
    })
    SystemsMaster selectOnlyBySId(@Param("sysId") String sysId);

    /**
     * 更新缩略图
     */
    @Update(value = {
            "UPDATE systems_master SET ",
            "icon = #{icon},icon_url = #{iconUrl} ",
            "WHERE s_id = #{sId}"
    })
    int updateSystemIcon(SystemsMaster systemsMaster);

    /**
     * 更新包含目标数量
     */
    @Update(value = {
            "UPDATE systems_master SET ",
            "include = #{include} ",
            "WHERE sys_id = #{sysId}"
    })
    int updateSystemsInclude(SystemsMaster systemsMaster);

    /**
     * 查询体系分析关联ID
     */
    @Select(value = {
            "SELECT target_id FROM systems_relation WHERE sys_id = #{sysId}"
    })
    List<String> selectSystemRelationTargetId(@Param("sysId") String sysId);


    /**
     * 查询共有属性统计
     */
    @Select(value = {
            "SELECT key_name,key,key_type FROM common_attribute WHERE sign = 1 AND info = #{info}"
    })
    @Results(value = {
            @Result(property = "keyName", column = "key_name"),
            @Result(property = "key", column = "key"),
            @Result(property = "keyType", column = "key_type")
    })
    List<CommonAttribute> findCommonIndex(@Param("info") String info);

    /**
     * 查询私有属性统计
     */
    @Select(value = {
            "SELECT key_name,key,key_type FROM special_attribute ",
            "WHERE type_id = (SELECT target_classify FROM target_base_data WHERE target_id = #{targetId}) AND info = #{info}"
    })
    @Results(value = {
            @Result(property = "keyName", column = "key_name"),
            @Result(property = "key", column = "key"),
            @Result(property = "keyType", column = "key_type")
    })
    List<SpecialAttribute> findSpecialIndex(@Param("targetId") String targetId, @Param("info") String info);

    /**
     * 查询已选择MB列表
     */
    @Select(value = {
            "<script>",
            "SELECT target_id,target_name,icon ",
            "FROM target_base_data WHERE ",
            "target_id IN ",
            "<foreach collection='idList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "<if test = 'keyword != null'> AND (target_name LIKE '%${keyword}%' OR country LIKE '%${keyword}%')</if>",
            " ORDER BY create_time ASC",
            "</script>"
    })
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name"),
            @Result(property = "icon", column = "icon")
    })
    List<TargetData> selectChoiceTarget(@Param("idList") List<String> targetIdList, @Param("keyword") String keyword);

    /**
     * 查询单个系统
     */
    @Select(value = {
            "SELECT sys_id,red_id,systems_name,systems_type,include_type,include,stat,remark,icon,icon_url,user_sign,create_time ",
            "FROM systems_master WHERE sys_id = #{sysId} LIMIT 1"
    })
    @Results(value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "redId", column = "red_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "systemsType", column = "systems_type"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "include", column = "include"),
            @Result(property = "stat", column = "stat"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "iconUrl", column = "icon_url"),
            @Result(property = "userSign", column = "user_sign"),
            @Result(property = "createTime", column = "create_time")
    })
    SystemsMaster selectSystemsOnly(@Param("sysId") String sysId);

    /**
     * 查询统计属性
     */
    @Select(value = "SELECT key,value,sign FROM info_element WHERE sys_id = #{sysId}")
    List<InfoElement> selectInfoBySId(@Param("sysId") String sysId);

    /**
     * 删除系统关联统计属性
     */
    @Delete(value = "DELETE FROM info_element WHERE sys_id = #{sysId}")
    int deleteInfo(@Param("sysId") String sysId);

    /**
     * 新增系统关联
     */
    @Insert(value = {
            "<script>",
            "INSERT INTO systems_relation ",
            "(sys_rel_id,sys_id,target_id,target_type) ",
            "VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.sysRelId},#{item.sysId},#{item.targetId},#{item.targetType})",
            "</foreach>",
            "</script>"
    })
    int addSystemsRelation(List<SystemsRelation> relations);

    /**
     * 删除系统
     */
    @Delete(value = "DELETE FROM systems_master WHERE sys_id = #{sysId}")
    int deleteSystem(@Param("sysId") String sysId);


    /**
     * 查询单个系统
     */
    @Select(value = {
            "SELECT sys_id,systems_name,include_type,remark,icon,icon_url,sort ",
            "FROM systems_master WHERE sys_id = #{sysId} LIMIT 1"
    })
    @Results(id = "systemsMap", value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "iconUrl", column = "icon_url")
    })
    SystemsMaster selectSystemOnlyBySId(@Param("sysId") String sysId);

    /**
     * 新增统计属性
     */
    @Insert(value = {
            "<script>",
            "INSERT INTO info_element ",
            "(id,s_id,sys_id,key,value,sign) ",
            "VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id},#{item.sId},#{item.sysId},#{item.key},#{item.value},#{item.sign})",
            "</foreach>",
            "</script>"
    })
    int addInfoElement(List<InfoElement> elements);

    /**
     * 查询选择MB列表
     */
    @Select(value = {
            "<script>",
            "SELECT target_id,target_name,icon ",
            "FROM target_base_data WHERE delete_sign = 1 ",
            "<foreach collection='targetList' item='item' index='index' open=' AND target_id IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "<if test = 'idList != null'> ",
            " AND target_id NOT IN ",
            "<foreach collection='idList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</if>",
            "<if test = 'keyword != null'>",
            " AND (target_name LIKE '%${keyword}%' OR country LIKE '%${keyword}%')",
            "</if>",
            " ORDER BY create_time DESC",
            "</script>"
    })
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name"),
            @Result(property = "icon", column = "icon")
    })
    List<TargetData> selectWaitChoiceTarget(@Param("targetList") List<String> targetList, @Param("idList") List<String> targetIdList, @Param("keyword") String keyword);

    /**
     * 新增系统
     */
    @Insert(value = {
            "INSERT INTO systems_master ",
            "(sys_id,red_id,systems_name,systems_type,include_type,include,remark,user_sign,task_sign,stat,icon,icon_url,create_time) ",
            "VALUES ",
            "(#{sysId},#{redId},#{systemsName},#{systemsType},#{includeType},#{include},#{remark},#{userSign},#{taskSign},#{stat},#{icon},#{iconUrl},CURRENT_TIMESTAMP)",
            "ON DUPLICATE KEY UPDATE red_id = #{redId}, systems_name = #{systemsName}, systems_type = #{systemsType}, include_type = #{includeType}, include = #{include}, remark = #{remark}, user_sign = #{userSign}, task_sign = #{taskSign}, stat = #{stat}, icon = #{icon},icon_url = #{iconUrl}"
    })
    int addSystem(SystemsMaster systemsMaster);

    /**
     * 删除体系关系
     */
    @Delete(value = "DELETE FROM systems_relationship WHERE sys_id = #{sysId}")
    int deleteShip(@Param("sysId") String sysId);

    /**
     * 删除体系关系
     */
    @Delete(value = {
            "<script>",
            "DELETE FROM systems_relationship WHERE sys_id = #{sysId} AND target_one NOT IN (",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "#{item}",
            "</foreach>",
            ") AND target_two NOT IN (",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "#{item}",
            "</foreach>",
            ")",
            "</script>"
    })
    int deleteShipByList(@Param("sysId") String sysId, @Param("list") List<String> list);

    /**
     * 查询当前系统指标列表
     */
    @Select(value = "SELECT key FROM info_element WHERE sys_id = #{sysId} AND sign = 1")
    List<String> selectInfoList(@Param("sysId") String sysId);

    /**
     * 查询单个系统
     */
    @Select(value = {
            "SELECT sys_id,systems_name,include_type,remark,icon,icon_url ",
            "FROM systems_master WHERE sys_id = #{sysId} LIMIT 1"
    })
    @Results(value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "iconUrl", column = "icon_url")
    })
    SystemsMaster selectSystemOnlyGetTypeIdBySId(@Param("sysId") String sysId);

    @Select(value = {
            "<script>",
            "SELECT a.target_id,a.target_name,b.value,c.type_name,d.hit_degree FROM  ",
            "(SELECT target_id,target_name,target_classify FROM target_base_data WHERE delete_sign = 1 ",
            "AND target_classify IN (",
            "<foreach collection='typeIds' item='item' index='index' separator=','>",
            "#{item}",
            "</foreach>",
            ") ",
            "<if test = 'targets != null'> ",
            "AND target_id NOT IN (",
            "<foreach collection='targets' item='item' index='index' separator=','>",
            "#{item}",
            "</foreach>",
            ")",
            "</if>",
            ") AS a ",
            "LEFT JOIN ",
            "(SELECT target_id,key,value,name FROM target_info WHERE key = #{key} ) AS b ",
            "ON a.target_id = b.target_id ",
            "LEFT JOIN ",
            "(SELECT type_id,type_name FROM target_type) AS c ",
            "ON a.target_classify = c.type_id ",
            "LEFT JOIN ",
            "(SELECT target_id,hit_degree FROM systems_relation WHERE sys_id = #{sysId} ) AS d ",
            "ON a.target_id = d.target_id ",
            "ORDER BY b.key DESC",
            "</script>"
    })
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name"),
            @Result(property = "indexData", column = "value"),
            @Result(property = "typeName", column = "type_name"),
            @Result(property = "hitDegree", column = "hit_degree")
    })
    List<TargetIndexList> selectWaitDataList(
            @Param("typeIds") List<String> typeIds,
            @Param("targets") List<String> targets,
            @Param("key") String key,
            @Param("sysId") String sysId);

    /**
     * 查询类别对应的名称
     */
    @Select(value = "SELECT type_name FROM target_type WHERE type_id = #{typeId}")
    String selectTypeName(@Param("typeId") String typeId);

    @Insert(value = {
            "<script>",
            "INSERT INTO systems_relation ",
            "(sys_rel_id,sys_id,target_id,hit_degree) ",
            "VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.sysRelId},#{item.sysId},#{item.targetId},#{item.hitDegree})",
            "</foreach>",
            "</script>"
    })
    int insertSystemsRelation(List<SystemsRelation> list);

    /**
     * 查询已选择目标的指标参数
     */
    @Select(value = {
            "<script>",
            "SELECT key,value,name FROM target_info ",
            "WHERE target_id IN ",
            "<foreach collection='targetList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    List<TargetInfo> selectConfirmIndexList(@Param("targetList") List<String> targetList);

    @Select(value = {
            "<script>",
            "SELECT a.target_id,a.target_name,b.value,c.type_name,d.hit_degree FROM  ",
            "(SELECT target_id,target_name,target_classify FROM target_base_data WHERE delete_sign = 1 ",
            "AND target_id IN (",
            "<foreach collection='targets' item='item' index='index' separator=','>",
            "#{item}",
            "</foreach>",
            ")",
            ") AS a ",
            "LEFT JOIN ",
            "(SELECT target_id,key,value,name FROM target_info WHERE key = #{key} ) AS b ",
            "ON a.target_id = b.target_id ",
            "LEFT JOIN ",
            "(SELECT type_id,type_name FROM target_type) AS c ",
            "ON a.target_classify = c.type_id ",
            "LEFT JOIN ",
            "(SELECT target_id,hit_degree FROM systems_relation WHERE sys_id = #{sysId} ) AS d ",
            "ON a.target_id = d.target_id ",
            "ORDER BY b.key DESC",
            "</script>"
    })
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name"),
            @Result(property = "indexData", column = "value"),
            @Result(property = "typeName", column = "type_name"),
            @Result(property = "hitDegree", column = "hit_degree")
    })
    List<TargetIndexList> selectConfirmDataList(
            @Param("targets") List<String> targets,
            @Param("key") String key,
            @Param("sysId") String sysId);

    @Select(value = {
            "SELECT target_id,target_name,target_classify,country,icon,sqlite_url,create_time,update_time,delete_sign ",
            "FROM target_base_data WHERE target_id = #{targetId}"
    })
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name"),
            @Result(property = "targetClassify", column = "target_classify"),
            @Result(property = "sqliteUrl", column = "sqlite_url"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "deleteSign", column = "delete_sign")
    })
    Target getTargetName(@Param("targetId") String targetId);

    /**
     * 查询当前体系指标列表
     */
    @Select(value = "SELECT key,value FROM info_element WHERE sys_id = #{sysId} AND sign = 1")
    List<InfoElement> selectInfoDataList(@Param("sysId") String sysId);

    /**
     * 初始化查询系统指标总和
     */
    @Select(value = {
            "<script>",
            "SELECT b.key,SUM(b.value) AS value,b.name FROM ",
            "(SELECT target_id FROM target_base_data WHERE delete_sign = 1 AND target_classify IN ",
            "<foreach collection='typeList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            ") AS a ",
            "LEFT JOIN ",
            "(SELECT target_id,key,value,name FROM target_info WHERE key IN ",
            "<foreach collection='keyList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            ") AS b ",
            "ON a.target_id = b.target_id WHERE b.target_id IS NOT NULL GROUP BY b.key",
            "</script>"
    })
    List<TargetInfo> selectInfoAll(
            @Param("typeList") List<String> typeIds,
            @Param("keyList") List<String> keyList);

    @Select(value = {
            "SELECT sys_id,systems_name,include_type,remark,icon,icon_url ",
            "FROM systems_master"
    })
    @Results(value = {
            @Result(property = "sysId", column = "sys_id"),
            @Result(property = "systemsName", column = "systems_name"),
            @Result(property = "includeType", column = "include_type"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "iconUrl", column = "icon_url")
    })
    List<SystemsMaster> getAll();

    @Select(value = {
            "<script>",
            "SELECT sys_id,systems_name,include_type,include,icon FROM systems_master",
            "WHERE 1=1 ",
            "<if test = 'typeList != null'>",
            "<foreach collection='typeList' item='item' index='index' open='AND (' separator='OR' close=')'>",
            " include_type LIKE '%${item}%' ",
            "</foreach>",
            "</if>",
            "<if test = 'keyword != null'> AND systems_name LIKE '%${keyword}%'</if>",
            " ORDER BY create_time DESC",
            "</script>"
    })
    @ResultMap(value = "systemsMap")
    List<SystemsMaster> selectSystemList(@Param("typeList") List<String> typeList, @Param("keyword") String keyword);

    @Select(value = {
            "<script>",
            "SELECT sys_id,systems_name,include_type,include,icon FROM systems_master",
            "WHERE task_sign = #{taskId} ",
            "<if test = 'typeList != null'>",
            "<foreach collection='typeList' item='item' index='index' open='AND (' separator='OR' close=')'>",
            " include_type LIKE '%${item}%' ",
            "</foreach>",
            "</if>",
            "<if test = 'keyword != null'> AND systems_name LIKE '%${keyword}%'</if>",
            " ORDER BY create_time DESC",
            "</script>"
    })
    @ResultMap(value = "systemsMap")
    List<SystemsMaster> selectListWuHan(@Param("taskId") String taskId, @Param("typeList") List<String> typeList, @Param("keyword") String keyword);

    /**
     * 查询关联目标同类别数量
     */
    @Select(value = {
            "SELECT COUNT(1) FROM systems_relation sr ",
            "LEFT JOIN target_base_data td ON sr.target_id = td.target_id ",
            " WHERE td.target_classify = (SELECT target_classify FROM target_base_data WHERE target_id = #{targetId}) ",
            "AND td.delete_sign = 1"
    })
    int selectClassifyCount(@Param("targetId") String targetId);

    @Delete(value = {
            "<script>",
            "DELETE FROM systems_relation WHERE sys_id = #{sys_id} AND ",
            "target_id IN ",
            "<foreach collection='targetList' item='item' index='index' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    int deleteSystemRelation(@Param("sys_id") String sysId, @Param("targetList") List<String> targetList);

    @Delete(value = {
            "DELETE FROM systems_relation WHERE sys_id = #{sys_id}"
    })
    int deleteRelation(@Param("sys_id") String sysId);

    /**
     * 查询系统目标类型与名称
     */
    @Select(value = {
            "<script>",
            "SELECT * FROM system_master WHERE 1=1 ",
            "<if test = 'stat != null'> ",
            "AND stat = #{stat} ",
            "</if>",
            "<if test = 'typeList != null'>",
            "<foreach collection='typeList' item='item' index='index' open='AND target_type IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</if>",
            "</script>"
    })
    @Results(value = {
            @Result(property = "sId", column = "s_id"),
            @Result(property = "systemName", column = "system_name")
    })
    List<SystemMaster> selectSystemChooseList(@Param("stat") String country, @Param("typeList") List<String> typeList);

    /**
     * 查询系统关联的目标id列表
     */
    @Select(value = {
            "<script>",
            "SELECT target_id FROM system_relation ",
            "<if test = 'systemList != null'>",
            "<foreach collection='systemList' item='item' index='index' open='WHERE s_id IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</if>",
            "</script>"
    })
    Set<String> selectSystemRelationTargetIdList(@Param("systemList") List<String> systemList);

    /**
     * 查询其他不包含的目标ID
     */
    @Select(value = {
            "<script>",
            "SELECT target_id FROM target_base_data ",
            "<foreach collection='targetList' item='item' index='index' open='WHERE target_id NOT IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    List<String> selectElseTargeIdtList(@Param("targetList") Set<String> targetList);

    /**
     * 查询体系列表
     */
    @Select(value = {
            "SELECT key,key_value FROM systems_else_table WHERE sys_id = #{sysId}"
    })
    @Results(value = {
            @Result(property = "key", column = "key"),
            @Result(property = "keyValue", column = "key_value")
    })
    List<SystemsElseData> selectSystemsElseDataList(@Param("sysId") String sysId);

    /**
     * 新增体系列表
     */
    @Insert(value = {
            "<script>",
            "INSERT INTO systems_else_table ",
            "(id,sys_id,key,key_value) ",
            "VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id},#{item.sysId},#{item.key},#{item.keyValue})",
            "</foreach>",
            "</script>"
    })
    int addSystemsElseData(List<SystemsElseData> list);

    /**
     * 删除体系列表
     */
    @Delete(value = "DELETE FROM systems_else_table WHERE sys_id = #{sysId}")
    int delSystemsElseData(@Param("sysId") String sysId);

    @Select(value = "SELECT td.target_id,td.target_name FROM systems_relation sr LEFT JOIN target_base_data td ON sr.target_id = td.target_id WHERE sr.sys_id = #{sysId}")
    @Results(value = {
            @Result(property = "targetId", column = "target_id"),
            @Result(property = "targetName", column = "target_name")
    })
    List<TargetData> selectTargetPull(@Param("sysId") String sysId);

    @Select(value = {
            "<script>",
            "SELECT s_id AS sId,system_name AS systemName FROM system_master ",
            "<foreach collection='list' item='item' index='index' open='WHERE s_id IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    List<Map<String, String>> selectSystemIdAndName(List<String> list);

    /**
     * 查询体系包含的所有目标
     * @param sysId
     * @param list
     * @return
     */
    @Select(value = {
            "<script>",
            "SELECT target_id FROM system_relation ",
            "<foreach collection='list' item='item' index='index' open='WHERE s_id IN (' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            " UNION ",
            "SELECT target_id FROM systems_relation WHERE sys_id = #{sysId}",
            "</script>"
    })
    List<String> selectSystemsHavaTargetId(@Param("sysId") String sysId, List<String> list);

    @Select("SELECT sys_id FROM systems_master WHERE systems_name = #{name} LIMIT 1")
    String selectSystemsName(@Param("name") String name);

    @Select("SELECT COUNT(1) FROM systems_relation WHERE sys_id = #{sysId} AND target_type = #{targetType}")
    int selectSystemsRelationCount(@Param("sysId") String sysId, @Param("targetType") String targetType);

    @Select(value = "SELECT sys_id FROM systems_master WHERE include_type LIKE '%${sId}%'")
    String selectHavaSystemIdSystems(@Param("sId") String sId);

    @Select(value = "SELECT sys_rel_id FROM systems_relation WHERE sys_id = #{sysId} AND target_id = #{targetId}")
    String selectSystemsRelationTargetId(@Param("sysId") String sysId, @Param("targetId") String targetType);

    @Select(value = "SELECT sys_id AS sysId,sort FROM systems_master LIMIT 1")
    SystemsMaster getOne();

}



